<template>
	<view class="content">
		<!-- <view class="search-block block">
			<CustomNav :isBack="true" :keyword="keyword" :custom="custom"></CustomNav>
		</view> -->
		<view class="block screen-block">
			<view class="screen-item">
				<picker :range="category" @change="bindCategory" range-key="typeName" class="picker category">
					{{category[categoryActive].typeName?category[categoryActive].typeName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<!-- <view class="screen-item" @click="distance">
				<view :class="optionActive==1?'active':''" @click="bindOption(1)" class="option">销量优先</view>
			</view>
			<view class="screen-item" @click="distance">
				<view :class="optionActive==2?'active':''" @click="bindOption(2)" class="option">好评优先</view>
			</view> -->
		</view>
		<view class="block list-block">
			<navigator hover-class="none" :url="'/pages/tourism_service/newDetail?id='+item.id"
				v-for="(item,index) in list" :key="item.id" class="list-item">
				<view class="photo-block">
					<image mode="aspectFill" :src="item.picUrl" class="photo"></image>
					<!-- <view class="position">{{item.position}}</view> -->
				</view>

				<view class="info-block">
					<view class="name">{{item.title}}</view>
					<view class="address">{{item.address}}</view>
					<view class="phone">电话：{{item.telPhone}}</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		postTravelList,
		postTravelTypeList,
		getFindAllLikes
	} from '@/api/tourism_service.js';
	export default {
		data() {
			return {
				keyword: '',
				custom: null,
				category: [],
				categoryActive: 0,
				optionActive: 0,
				list: []
			}
		},
		onShow() {
			this.findTypeList()
		},
		methods: {
			bindCategory(e) {
				this.categoryActive = e.detail.value;
				this.findList()
			},
			bindOption(index) {
				this.optionActive = index;
				this.findList()
			},
			findList() {
				let travelType = this.category[this.categoryActive].id
				let sortType = this.optionActive
				postTravelList({
					page: 0,
					limit: 0,
					sortType,
					travelType
				}).then((res) => {
					if (res.code == 1) {
						if (res.data != null) {
							this.list = res.data
							console.log(this.list)
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			findTypeList() {
				postTravelTypeList({}).then((res) => {
					if (res.code == 1) {
						if (res.data != null) {
							this.category = res.data
							this.findList()
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			getSearchList() {
				let title = this.title
				getFindAllLikes({
					title
				}).then((res) => {
					if (res.code === 1) {
						this.list = res.data;
						console.log(this.list)
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败！',
					})
				})
			},

		},
		mounted(e) {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad() {
			uni.$on('getSearchInput', (e) => {
				this.title = e;
				this.getSearchList()
			})
			this.findTypeList()
		}
	}
</script>

<style lang="scss">
	.content {
		.block.search-block {
			background: $color-primary;
			overflow: hidden;
		}

		.block.screen-block {
			display: flex;
			flex-direction: row;
			background: $color-primary;
			align-items: center;
			padding: 20rpx;

			.screen-item {
				display: flex;
				margin-left: 30rpx;
				color: $color-border-lighter;
				align-items: center;
				font-size: 30rpx;
				flex-grow: 1;

				.picker {
					display: flex;
					justify-content: center;
				}

				.picker.category {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.iconfont {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-weight: normal;
				}

				.option.active {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}
			}
		}

		.block.label-block {
			display: flex;
			flex-direction: row;
			overflow-x: scroll;
			width: 100%;
			padding: 20rpx 0;

			.label-item {
				border-radius: 30rpx;
				color: $color-regular-text;
				font-size: 26rpx;
				padding: 10rpx 30rpx;
				background: $color-border-extralight;
				margin: 0 10rpx;
				flex: none;
			}
		}

		.block.list-block {
			padding: 0 30rpx;
			display: flex;
			flex-direction: column;

			.list-item {
				display: flex;
				flex-direction: row;
				padding: 20rpx 0;
				border-bottom: 1px solid #efefef;

				.photo-block {
					.photo {
						width: 100%;
						height: 100%;
					}

					overflow: hidden;
					width: 230rpx;
					height: 230rpx;
					border-radius: 12rpx;
					margin-right: 20rpx;
					position: relative;

					.position {
						display: flex;
						align-items: center;
						justify-content: center;
						padding: 4rpx 20rpx;
						color: #fff;
						background: rgba(0, 0, 0, 0.7);
						font-size: 24rpx;
						border-radius: 0 0 20rpx 0;
						position: absolute;
						top: 0;
						left: 0;
					}

					.category {
						height: 40rpx;
						font-size: 26rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						width: 100%;
						color: #fff;
						background: rgba(0, 0, 0, 0.7);
						position: absolute;
						bottom: 0;
						left: 0;
					}
				}

				.info-block {
					width: calc(100% - 250rpx);
					display: flex;
					flex-direction: column;
					position: relative;

					.name {
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						font-size: 32rpx;
						font-weight: bold;
						margin-bottom: 10rpx;
					}

					.address,
					.phone {
						color: #3d3d3d;
						margin-top: 10rpx;
						font-size: 28rpx;
					}
				}
			}

			.list-item.attractions:last-child {
				border: none;
			}
		}
	}
</style>